// CyTargetLinker,
// a Cytoscape plugin to extend biological networks with regulatory interaction
// Copyright 2011-2012 BiGCaT Bioinformatics
//
// This class was adapted from the PDF Forms Designer project
// Project Info:  http://pdfformsdesigne.sourceforge.net
//
//	  This library is free software; you can redistribute it and/or
//    modify it under the terms of the GNU General Public
//    License as published by the Free Software Foundation; either
//    version 2.1 of the License, or (at your option) any later version.
//
package org.pdf.forms.gui.properties.customcomponents.colorcombobox;

import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;

import javax.swing.DefaultListCellRenderer;
import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
import javax.swing.border.LineBorder;


public class ColorCellRenderer implements ListCellRenderer {
	protected DefaultListCellRenderer defaultRenderer = new DefaultListCellRenderer();

	// Width doesn't matter as the combo box will size
	private final static Dimension preferredSize = new Dimension(0, 20);

	public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) {
		JLabel renderer = (JLabel) defaultRenderer.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
		if (value instanceof Color) {
			renderer.setBackground((Color) value);
			renderer.setForeground((Color) value);
		}
		if (cellHasFocus || isSelected) {
			renderer.setBorder(new LineBorder(Color.DARK_GRAY));
		} else {
			renderer.setBorder(null);
		}

		renderer.setPreferredSize(preferredSize);
		return renderer;
	}
}